<include file="Public/header"/>
<include file="Public/menu"/>

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            首页
            <small>结算</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">店铺结算账单</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="tab-content">
            <div class="tab-pane active" id="tab_0">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"></h3>
                        <div class="form-inline pull-right">
                            <form action="{:U('index')}" method="get" pjax-container="">
                                <fieldset>
                                    <div class="input-group input-group-sm">
                                        <div class="input-group input-group-sm">
                                            <input type="hidden" name="search_field" value="{$search_field|default='account_id'}">
                                            <input type="text" class="form-control" placeholder="请输入查询单号" name="search" value="{$search}">
                                        </div>
                                    </div>

                                    <div class="input-group input-group-sm">
                                        <div class="input-group-btn">
                                            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i>
                                            </button>
                                        </div>
                                    </div>
                                </fieldset>
                            </form>
                        </div>
                        <!-- todo -->
                        <div class="btn-group pull-right" style="margin-right: 10px">
                            <a href="javascript:;" class="btn btn-sm btn-success"><i
                                    class="fa fa-save"></i>&nbsp;&nbsp;生成结算报表</a>
                        </div>

                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tbody>
                            <tr>
                                <th>ID<a class="fa fa-fw fa-sort" href="{:U('index',array('p'=>$p,'order_field'=>'id','order'=>$order), '')}"></a></th>
                                <th>结算单号</th>
                                <th>结算时间</th>
                                <th>生成日期</th>
                                <th>结算金额</th>
                                <th>经办人</th>
                                <th>划账日期</th>
                                <th>备注说明</th>
                                <th>附图</th>
                                <th>结算状态</th>
                            </tr>
                            <volist name="list" id="vo" key="k">
                            <tr>
                                <td>{$k}</td>
                                <td><a href="{:U('view',array('id'=> $vo['id']))}">{$vo.account_id}</a></td>
                                <td>{$vo.start_time|date='Y-m-d', ###} - {$vo.end_time|date='Y-m-d', ###}</td>
                                <td>{$vo.create_time|date='Y-m-d', ###}</td>
                                <td><code>{$vo.final_accountMoney}</code></td>
                                <td>{$vo.handle_name}</td>
                                <td>
                                    <if condition="$vo['update_time'] gt 0">
                                        {$vo.update_time|date='Y-m-d', ###}
                                    </if>
                                </td>
                                <td>{$vo.remark}</td>
                                <td></td>
                                <td>
                                    <if condition="$vo['state'] eq 0">
                                        结算中
                                    <elseif condition="$vo['state'] eq 1"/>
                                        完成
                                    <elseif condition="$vo['state'] eq 2"/>
                                        <code>有异议</code>
                                    </if>
                                </td>
                            </tr>
                            </volist>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">

                        <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>
                        {$page}
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>

        </div>
    </section>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">×
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    生成结算报表
                </h4>
            </div>
            <form action="{:U('createReport')}">
                <div class="modal-body">
                    <div class="btn-group">时间段</div>

                    <input id="start_time" class="form-control" type="text" name="start_time" value="{$_GET['start_time']|default='开始时间'}" readonly>
                    <div class="btn-group">~</div>
                    <input id="end_time" class="form-control" type="text" name="end_time" value="{$_GET['end_time']|default='结束时间'}" readonly>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                    <button type="submit" class="btn btn-primary  mark-submit">
                        提交
                    </button>
                </div>
            </form>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- 底部 -->
<include file="Public/common_footer"/>
<script src="/Public/layer/layer.js"></script>
<script src="/Public/admin/laydate/laydate.js"></script>
<link rel="stylesheet" href="/Public/admin/jedate/jedate.css" />
<script src="/Public/admin/jedate/jedate.js"></script>

<script type="text/javascript">
    function layerTime(){
        var start = {
            elem: "#start_time",
            format: 'YYYY-MM-DD',
            min: '1970-01-01 00:00:00', //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: false,
            istoday: false,
            choose: function(datas){
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: "#end_time",
            format: 'YYYY-MM-DD',
            min: '1970-01-01 00:00:00',
            max: '2099-06-16 23:59:59',
            istime: false,
            istoday: false,
            choose: function(datas){
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
    }

    $(function () {
        layerTime();
        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        $('._delete').click(function () {
            if(!confirm("确认问题已处理")){
                return false;
            }
            var id = $(this).attr('data-id');
            if (vendor_id) {

                $.ajax({
                    type: "POST",
                    url: "{:U('del')}",
                    data: {id:id},
                    success: function(msg){
                        alert(msg.message);
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            }
        });

        $('.batch-delete').on('click',function(e){
            if(!confirm("确认批量删除")){
                return false;
            }
            var data = [];
            $(".grid-item[type='checkbox']:checked").each(function (i) {
                var vendor_id = $(this).attr('data-id');
                data.push(vendor_id);
                $(this).parent().parent().remove();
            });
            if (data) {
                $.ajax({
                    type: "POST",
                    url: "{:U('vendor/del')}",
                    data: {vendor_id:data},
                    success: function(msg){
                        console.log(msg.message);
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            }
        });

        $('.btn-success').on('click', function () {
            $('#myModal').modal('show');
        });


    });
</script>